<template>
  <div>
    <div class="title quoteline mb-12">
      <div class="text-left quotet1 text-14 text-bold mb-12">
        {{ $t("deal.placeorder") }}
      </div>
      <div class="curent-time">
        <div class="quotet3 text-10 mb-2">{{ $t("lever.nowtime") }}:</div>
        <div class="personlink family-d text-bold text-14">
          {{ state.time }}
        </div>
      </div>
    </div>

    <div class="flex js-sp mb-12" v-if="state.islogin">
      <div class="text-10">
        <span class="quotet3" style="margin-inline-end:8px">
          {{ $t("deal.available") }}
        </span>
        <span class="family-d quotet2 text-bolder inline-block"
          >{{ $currency(state.info?.balance) }} USDT</span
        >
      </div>
      <img
        v-if="!virtual_wallet"
        @click="state.dialogHuazhuan = true"
        src="@/assets/images/order.png"
        class="order-icon"
        alt
      />
    </div>
    <div
      class="cus-select radius quoteline mb-20 lever-input flex js-sp align-center"
    >
      <el-input
        :placeholder="$t('deal.transamount')"
        v-model="state.secondParam.deal_price"
        @input="transferNumberChange"
        :controls="false"
        placeholder-color="red"
        class="quotet3 customer-input"
        type="text"
      />
      <!-- <el-input-number
        :placeholder="$t('deal.transamount')"
        :controls="false"
        v-model="state.secondParam.deal_price"
      ></el-input-number> -->
      <span class="text-12 text-link flex-shrink-0 point" @click="getAll">{{
        $t("fiat.all")
      }}</span>
    </div>
    <div
      class="cus-select quoteline radius flex js-sp align-center mb-16 point"
      @click="state.isSelect = !state.isSelect"
      v-clickout="closeSelect"
    >
      <span class="quotet3">
        {{ state.order_time ? state.order_time : $t("formTip.chooseBuyTime") }}
      </span>
      <div class="select-num text-right">
        <i
          class="el-icon-arrow-down quotet2 text-14"
          v-if="!state.isSelect"
        ></i>
        <i class="el-icon-arrow-up quotet2 text-14" v-else></i>
        <ul class="num-box text-left quotebg radius" v-if="state.isSelect">
          <li
            class="num quotet2 text-14 times"
            v-for="(item, index) in state.simpleData"
            @click.stop="
              choiceTime(
                item.id,
                item.seconds,
                item.min_price,
                item.max_price,
                item.handling_fee,
                item.handling_fee_type
              )
            "
            :key="index"
          >
            <div class="break-all">
              <span>{{ item.seconds }}</span>
              <span
              >
                ({{
                 item.profit_ratio*100
                }}%)
              </span>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <!-- <div class="text-left mb-16">
      <el-checkbox v-model="state.checked">
        <span class="text-10 quotet3 pd-rt-xs">
          {{ $t("lever.timed") }}
        </span>
      </el-checkbox>
    </div> -->
    <div class="mb-16 select-time" v-if="state.checked">
      <el-time-select
        v-model="state.timeObj.selectTime"
        :start="state.timeObj.start"
        step="00:01"
        :end="state.timeObj.end"
        :placeholder="$t('lever.selecttime')"
        @focus="initTimeP"
        popper-class="popper-dark"
      >
      </el-time-select>
    </div>
    <!-- 登录状态 -->
    <div class="btnbox share-color mb-32" v-if="state.islogin">
      <div class="btn green-bg  point" @click="buy(1)">
        {{ $t("lever.buyup") }}
      </div>
      <div class="btn red-bg  point" @click="buy(2)">
        {{ $t("lever.buyfall") }}
      </div>
      <div
        v-if="isFollow && !virtual_wallet"
        class="btn text-login border radius point text-bolder"
        @click="toPath('/documentary')"
      >
        {{ $t("stock.oneClickCopy") }}
      </div>
    </div>
    <!-- 未登录 -->
    <div
      class="tralation-btn islogin text-12 flex align-center js-ct mb-32 radius text-bold"
      v-else
    >
      <router-link to="/login" class="point">{{
        $t("login.login")
      }}</router-link>
      <div class="color_42  lr-5">{{ $t("login.or") }}</div>
      <router-link to="/register" class="point">{{
        $t("register.register")
      }}</router-link>
    </div>
    <!-- <div
      class="text-14 text-left share-color text-bold mb-20"
      v-if="state.islogin && !virtual_wallet"
    >
      {{ $t("lever.assets") }}
    </div>
    <div class="flex align-center js-sp">
      <div class="activetab point text-login text-12 flex-grow-1">入金</div>
      <div class="activetab point text-login text-12 flex-grow-1 mg-lf-xs">
        汇兑
      </div>
    </div> -->
    <!-- <div
      class="buycount text-bold point"
      v-if="state.islogin && !virtual_wallet"
    >
      <div class="btn acbtn share-color radius">买币</div>
      <div
        class="btn text-login border radius point"
        @click="state.dialogHuazhuan = true"
      >
        {{ $t("lever.transfer") }}
      </div>
    </div> -->

    <!-- 确认下单 -->
    <el-dialog
      :title="
        state.type === 1
          ? $t('lever.confirmorder')
          : state.type === 2
          ? $t('lever.processing')
          : $t('lever.settlement')
      "
      v-model="state.dialogConfirm"
      top="230px"
      width="400px"
      v-if="state.dialogConfirm"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <!-- 确认下单 -->
      <div class="confirm-box" v-if="state.type === 1">
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("exchange.type") }}:</span>
          <div class="flex js-sp">
            <span
              class="text-bold mr-4"
              :class="
                state.secondParam.order_type === 1 ? 'text-green' : 'text-red'
              "
            >
              {{
                state.secondParam.order_type === 1
                  ? $t("lever.buyup")
                  : $t("lever.buyfall")
              }}
            </span>
            <span class="text-bolder quotet2">
              <!-- {{ gettrading.currency_name }} -->  ----
            </span>
          </div>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("exchange.currentPrice") }}:</span>
          <span class="text-bolder quotet2">{{ $currency(nowprice) }}</span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("stock.orderAmount") }}:</span>
          <span class="text-bolder quotet2">
            {{ $currency(CountDealPrice(state.secondParam.deal_price)) }}
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("lever.duration") }}:</span>
          <span class="text-bolder personlink">{{ state.order_time }}</span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("assets.handlingFee") }}:</span>
          <span class="text-bolder quotet2">
            {{
              state.handling_fee_type == 2
                ? state.handling_fee
                : reduceFix(
                    state.secondParam?.deal_price,
                    CountDealPrice(state.secondParam?.deal_price)
                  )
            }}</span
          >
        </div>
        <div class="text-16 flex js-sp point" v-loading="state.loading">
          <div
            class="nobtn quotet3 confirm-btn radius"
            @click="state.dialogConfirm = false"
          >
            {{ $t("cancel") }}
          </div>
          <div class="acbtn share-color confirm-btn radius" @click="placeOrder">
            {{ $t("confirm") }}
          </div>
        </div>
      </div>
      <!-- 进行中 -->
      <div class="confirm-box" v-else>
        <div class="flex js-ct align-center top" v-if="state.type === 2">
          <span class="text-10 quotet3">{{ $t("lever.delivery") }}：</span>
          <span class="family-d text-bolder text-18 personlink">
            <count-down
              v-if="state.dialogConfirm"
              :end-time="
                Date.parse(
                  new Date(getTimeZoneDate(state.secondDetail?.close_time))
                ) /
                  1000 +
                  ''
              "
              :start-time="state.secondDetail?.system_time"
            ></count-down>
          </span>
        </div>
        <div class="flex js-ct align-center top" v-else>
          <span
            v-if="getProfit > 0"
            class="family-d text-bolder text-18"
            :class="getProfit < 0 ? 'text-red' : 'text-green'"
            >+</span
          >
          <span
            class="family-d text-bolder text-18"
            :class="getProfit < 0 ? 'text-red' : 'text-green'"
          >
            {{ $currency(getProfit) }}
            USDT
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20" v-if="state.type === 2">
          <span class="quotet3">{{ $t("lever.opentime") }}:</span>
          <span class="text-bolder quotet2 family-d">
            {{ getTimeZoneDate(state.secondDetail.open_time) }}
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("lever.buyingprice") }}:</span>
          <span class="text-bolder quotet2 family-d">
            {{ $currency(state.secondDetail.open_price) }}
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20" v-if="state.type === 2">
          <span class="quotet3">{{ $t("exchange.currentPrice") }}:</span>
          <span class="text-bolder quotet2 family-d">{{ nowprice }}</span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("exchange.type") }}:</span>
          <div class="flex js-sp">
            <span
              class="text-bold mr-4"
              :class="
                state.secondDetail.order_type === 1 ? 'text-green' : 'text-red'
              "
            >
              {{
                state.secondDetail.order_type === 1
                  ? $t("lever.buyup")
                  : $t("lever.buyfall")
              }}
            </span>
            <span class="text-bolder quotet2 family-d">
              {{ gettrading.currency_name }}
            </span>
          </div>
        </div>
        <div class="flex js-sp text-14 mb-20" v-if="state.type === 4">
          <span class="quotet3">{{ $t("lever.duration") }}:</span>
          <span class="text-bolder quotet2 family-d">
            {{ state.secondDetail.order_show_time }}
          </span>
        </div>
        <div
          class="flex js-sp text-14"
          :class="state.type === 2 ? 'mb-20' : 'mb-32'"
        >
          <span class="quotet3">{{ $t("stock.orderAmount") }}:</span>
          <span class="text-bolder quotet2 family-d">
            {{ $currency(state.secondDetail.deal_price) }}
          </span>
        </div>
        <div
          class="flex js-sp text-14 mb-32"
          v-if="state.type === 2 && state.remainTime < 0"
        >
          <div class="quotet3">{{ $t("lever.expectedprofit") }}:</div>
          <div
            class="text-bolder family-d flex align-center "
            :class="getProfit < 0 ? 'text-red' : 'text-green'"
          >
            <div v-if="getProfit > 0">+</div>
            {{ $currency(getProfit) }}
          </div>
        </div>
        <div class="continue acbtn share-color text-16 radius" @click="cutinu">
          {{ $t("lever.continue") }}
        </div>
      </div>
    </el-dialog>

    <!-- 挂单中弹窗 -->
    <el-dialog
      :title="$t('exchange.pengding')"
      v-model="state.pendingDialog"
      v-if="state.pendingDialog"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      top="230px"
      width="400px"
    >
      <div class="confirm-box">
        <!-- <div class="flex js-ct align-center top">
          <span class="text-10 quotet3">{{ $t("lever.opentiming") }}：</span>
          <span class="family-d text-bolder text-18 personlink">{{
            getTimeZoneDate(state.secondDetail.open_time)
          }}</span>
        </div> -->
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("exchange.type") }}:</span>
          <div class="flex js-sp">
            <span
              class="text-bold mr-4"
              :class="
                state.secondDetail.type == 1 ? 'text-green' : 'text-red'
              "
            >
              {{
                state.secondDetail.type == 1
                  ? $t("lever.buyup")
                  : $t("lever.buyfall")
              }}
            </span>
            <span class="text-bolder quotet2 family-d">
              <!-- {{ gettrading.currency_name }} -->
            </span>
          </div>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("lever.duration") }}:</span>
          <span class="text-bolder quotet2">
            {{ state.secondDetail.order_show_time }} s
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("stock.orderAmount") }}:</span>
          <span class="text-bolder quotet2">
            {{ $currency(state.secondDetail.deal_price) }}
          </span>
        </div>
        <div class="flex js-sp text-14 mb-20">
          <span class="quotet3">{{ $t("exchange.handlingFee") }}:</span>
          <span class="text-bolder quotet2">
            {{ $currency(state.secondDetail.handling_fee) }}
          </span>
        </div>
        <div class="continue acbtn share-color text-16 radius" @click="cutinu">
          {{ $t("lever.continue") }}
        </div>
      </div>
    </el-dialog>
    <!-- 划转 -->
    <el-dialog
      :title="$t('assets.fundTransfer')"
      v-if="state.dialogHuazhuan"
      v-model="state.dialogHuazhuan"
      width="400px"
    >
      <Huazhuan
        :type="22"
        :downplace="true"
        @close="state.dialogHuazhuan = false"
        @getbalance="getinfo"
      />
    </el-dialog>
    <VerifiedBox
      :text="$t('formTip.certificationTip1')"
      :dialog="state.dialogVerfiedTip"
      :type="state.realNameType"
      @onconfirm="onConfirm"
      @viewSafeStatus="onConfirm"
      @oncancer="onCancel"
    />
  </div>
</template>

<script>
import { reactive, onMounted, computed, watch } from "vue";
import { formatDate, formatTimeZone, getTimeZoneDate } from "@/utils/times.js";
import { useStore } from "vuex";
import {
  orderSecondLeverInfo,
  orderSecondLever,
  secondOrderDetail,
  currencyMatchList,
} from "@/api/currency";
import {
  microtrade_submit,
  microtradeLists
} from "@/api/assets";

import {
  demoorderSecondLeverInfo,
  demoorderSecondLever,
  demosecondOrderDetail,
} from "@/api/demo";
import UseSystemSetting from "@/commonapi/useSystemSetting";
import { ElMessage } from "element-plus";
import {
  countWinlose,
  toBeNumber,
  formatDecimal,
  decimalDigitsInputFilter,
  floorDigitsInputFilter,
} from "@/utils/common";
import CountDown from "@/components/countDown/index.vue";
// import Downtime from "@/components/downTime";
import Huazhuan from "@/components/personModel/assets/huazhuan.vue";
import { useI18n } from "vue-i18n";
import VerifiedBox from "@/components/verifiedBox/index.vue";
import { useRouter } from "vue-router";
import { rideFix, exceptFix, reduceFix, addFix } from "@/utils/precisionMath";

export default {
  name: "SecondOrder",
  props: { nowprice: Number, limitPrice: Number },
  emits: ["refreshParent"],
  components: { Huazhuan, VerifiedBox, CountDown },
  setup(props, ctx) {
    const $store = useStore();
    const { t } = useI18n();
    const state = reactive({
      account_type_id:4,
      currency_id:2,
      match_id:3,
      realNameType: 0,
      time: "2020-21-12 20:23:12",
      isSelect: false, //选择时间
      islogin: $store.state.user.token ? true : false,
      isopenlever: $store.state.user.userInfo
        ? $store.state.user.userInfo.user_lever_status
        : false,
      dialogConfirm: false, //确认订单
      pendingDialog: false, //挂单中弹窗
      type: 1, //1确认下单 2进行中 3到期结算完成
      newOrder: false, //是否关闭弹窗打开新的下单弹窗
      info: {},
      order_time: 0,
      secondParam: {},
      checked: false,
      secondDetail: {},
      countTimer: null,
      dialogHuazhuan: false,
      timeObj: {
        selectTime: "",
        start: "",
        end: "",
        dateTime: "",
      },
      simpleData: [],
      dialogVerfiedTip: false,
      min_price: 0,
      max_price: 0,
      handling_fee: 0,
      handling_fee_type: 2,
      order_time_id: 0,
      remainTimer: null, //开仓时间预测倒计时
      remainTime: 0,
    });
    // 获取开关状态
    const { virtual_wallet } = UseSystemSetting();
    const getProfit = computed(() => {
      let nowprice =
        state.secondDetail?.order_status === 2
          ? props.nowprice
          : state.secondDetail?.close_price;
      return formatDecimal(
        Number(
          countWinlose(
            nowprice,
            state.secondDetail.order_type,
            state.secondDetail.open_price,
            state.secondDetail.deal_price,
            state.secondDetail.profit_ratio
          )
        ),
        gettrading.value?.price_accuracy
      );
    });
    const isProfitShow = () => {
      if (state.remainTime === 0) {
        let remainTime =
          Date.parse(getTimeZoneDate(new Date(state.secondDetail.open_time))) -
          state.secondDetail.system_time;
        state.remainTime = remainTime;
      }

      state.remainTime = state.remainTime - 1000;
    };
    /**
     * methods
     */
    const gettrading = computed(() => {
      return $store.state.exchange.second_data;
    });
    const revokeOrder = computed(() => {
      return $store.state.exchange.revokeOrder;
    });
    watch(
      () => gettrading.value?.id,
      (val) => {
        if (val) {
          console.log(gettrading,'gettrading---------------')
          getinfo();
        }
      }
    );
    watch(
      () => [revokeOrder.value, virtual_wallet.value],
      () => {
        if ($store.state.user?.token) {
          getinfo();
        }
      }
    );
    const refresh = () => {
      if (state.pendingDialog || state.dialogConfirm) {
        if (state.secondDetail.id && state.type === 2) {
          getDetail(state.secondDetail.id);
        }
      }
    };
    // 下单为正数
    const transferNumberChange = (val) => {
      if (val) {
        let tempV = toBeNumber(val);
        state.secondParam.deal_price = decimalDigitsInputFilter(
          tempV,
          gettrading.value?.price_accuracy
        );
      }
    };
    //  获取秒合约交易余额
    const getinfo = () => {
      // || !gettrading.value?.id
      if (!$store.state.user.token) {
        return;
      }
      console.log('详情信息')
      // virtual_wallet.value
      //   ? demoorderSecondLeverInfo
      //   :
      let setFun =  orderSecondLeverInfo;
      // 4 账户表示期权 pay_id: 2, // id 表示usdt
      setFun({currency_id:state.currency_id,account_type_id:state.account_type_id}).then((res) => {
        state.info = res.data;
      });
    };
    // 选择时间
    const choiceTime = (
      id,
      item,
      min_price,
      max_price,
      handling_fee,
      handling_fee_type
    ) => {
      state.order_time_id = id;
      state.order_time = item;
      state.min_price = min_price;
      state.max_price = max_price;
      state.handling_fee = handling_fee;
      state.handling_fee_type = handling_fee_type;
      closeSelect();
    };
    const closeSelect = () => {
      state.isSelect = false;
    };
    const setTime = () => {
      setInterval(() => {
        state.time = formatDate(Date.parse(new Date()));
      }, 1000);
    };
    const $router = useRouter();
    const onConfirm = () => {
      state.dialogVerfiedTip = false;
      $router.push("/person/Authentication");
    };
    const onCancel = () => {
      state.dialogVerfiedTip = false;
    };
    //是否需要实名
    const isVerified = computed(() => {
      let list = $store.state.user.systemInfo;
      let flag = false;
      list.forEach((ele) => {
        if (ele.key === "verify_switch") {
          if (
            ele.value[2] &&
            $store.state.user.securityInfo.user_auth_level !== 2
          ) {
            if ($store.state.user.securityInfo.user_auth_level !== 4) {
              state.realNameType = 1;
            }
            flag = true;
          }
        }
      });
      return flag;
    });
    const isFollow = computed(() => {
      let list = $store.state.user.systemInfo;
      let flag = false;
      list.forEach((ele) => {
        if (ele.key === "follow_status") {
          flag = ele.value;
        }
      });
      return flag;
    });
    // 计算下单金额
    const CountDealPrice = (val) => {
      let price = 0;
      if (val) {
        if (state.handling_fee_type == 1) {
          price = exceptFix(val, addFix(1, exceptFix(state.handling_fee, 100)));
        } else {
          price = reduceFix(val, state.handling_fee);
        }
      }
      return floorDigitsInputFilter(price, gettrading.value?.price_accuracy);
    };
    // 买涨买跌
    const buy = (type) => {
      console.log(type,'买涨买跌')
      if (isVerified.value) {
        state.dialogVerfiedTip = true;
        return false;
      }

      if (!state.secondParam.deal_price) {
        ElMessage.error(t("deal.enter") + t("deal.transamount"));
        return;
      }
      if (state.order_time === 0) {
        ElMessage.error(t("lever.selectdura"));
        return;
      }
      // if (
      //   state.max_price &&
      //   rideFix(state.secondParam.deal_price, 1) > state.max_price
      // ) {
      //   ElMessage.error(
      //     t("cancelFinancial.priceNoBig", { price: state.max_price })
      //   );
      //   return;
      // }
      // if (
      //   state.min_price &&
      //   rideFix(state.secondParam.deal_price, 1) < state.min_price
      // ) {
      //   ElMessage.error(
      //     t("cancelFinancial.priceNoLow", { price: state.min_price })
      //   );
      //   return;
      // }
      // if (!state.min_price && state.secondParam.deal_price < props.limitPrice) {
      //   ElMessage.error(t("formTip.secondTradeTip"));
      //   return;
      // }
          console.log('到这里了吗？')
      state.secondParam.order_type = type;
      // gettrading.value?.second_lever_time_list.forEach((item) => {
      //   if (item.id === state.order_time_id) {
      //     state.secondParam.id = item.id;
      //     state.secondParam.handling_fee = item.handling_fee;
      //     state.secondParam.handling_fee_type = item.handling_fee_type;
      //   }
      // });
      // state.secondParam.type = state.checked ? 2 : 1;
      state.secondParam.type = type;
      state.secondParam.currency_match_id = gettrading.value?.id;
      // 判断是否为定时下单
      if (state.checked) {
        if (state.timeObj.selectTime) {
          const timeTemp = new Date(
            `${state.timeObj.dateTime} ${state.timeObj.selectTime}:00`
          );
          const time = formatTimeZone(timeTemp, 8);
          state.secondParam.order_time = formatDate(time);
          placeOrder();
        }
      } else {
        // state.type = 1;
        console.log(state.secondParam);
        //下面这个是确认弹框
        // state.dialogConfirm = true;
        //直接调用下单
        placeOrder()
      }
    };
    // 获取详情
    const getDetail = (id) => {
      let setFun = virtual_wallet.value
        ? demosecondOrderDetail
        : secondOrderDetail;
      setFun(id)
        .then((res) => {
          state.loading = false;
          if (res.code === 1) {
            state.secondDetail = res.data;
            console.log(state.checke,'state.checke')
            
            if (!state.checked) {
              state.type = 2;
              state.remainTime = 0;
              // 清除倒计时，重置剩余时间
              if (state.remainTimer) {
                clearInterval(state.remainTimer);
                state.remainTimer = null;
              }
              state.remainTimer = setInterval(function() {
                isProfitShow();
                if (state.remainTimer && state.remainTime + 1000 < 0) {
                  clearInterval(state.remainTimer);
                  state.remainTimer = null;
                }
              }, 1000);
            }
            if (res.data.order_status === 4) {
              state.type = 4;
            }
          }
        })
        .catch(() => {
          state.loading = false;
        });
    };
    // 获取交易对
    const getTrading = () => {
      let data = { match_id:state.match_id};
      currencyMatchList(data)
        .then((res) => {
          state.simpleData = res.data;
          console.log('simpleData',state.simpleData)
        })
        .catch(() => {});
    };
    // 确定下单`
    const placeOrder = () => {
      if (
        state.handling_fee_type == 2 &&
        CountDealPrice(state.secondParam.deal_price) <= 0
      ) {
        ElMessage.error(
          t("formTip.secondOrderTip", { num: state.handling_fee })
        );
        return false;
      }
      state.loading = true;
      state.secondParam.match_id=state.match_id
      state.secondParam.currency_id=state.currency_id
      state.secondParam.seconds=state.order_time
      state.secondParam.number=state.secondParam.deal_price
      state.secondParam.range_id=state.order_time_id
    

      console.log(state.secondParam,'看下这些是啥参数0000')
      // let setFun = virtual_wallet.value
      //   ? demoorderSecondLever
      //   : orderSecondLever;
      let setFun=microtrade_submit;
      setFun(state.secondParam)
        .then((res) => {
          if (res.code === 1) {
            ElMessage({
              type: "success",
              message: res.msg,
            });
            ctx.emit("refreshParent");
            getinfo();
            // getDetail(res.data.id);

            state.secondDetail.type=res.data.type
            state.secondDetail.order_show_time=res.data.seconds
            state.secondDetail.deal_price=res.data.number
            state.secondDetail.handling_fee=res.data.fee
            console.log('state.checked',state.checked)
            state.pendingDialog = true;
            if (state.checked) {
              state.pendingDialog = true;
            }
          }else{
            ElMessage.error(res.msg);
          }
        })
        .catch((err) => {
          state.loading = false;
          ElMessage.error(err.msg);
        });
      // if (!state.min_price &&state.secondParam.deal_price >= props.limitPrice) {

      // } else {
      //   ElMessage.error(t("formTip.secondTradeTip"));
      //   // state.loading = false;
      // }
    };
    // 点击继续下单
    const cutinu = () => {
      state.pendingDialog = false;
      // if (state.checked) {
      //   state.pendingDialog = false;
      // } else {
      //   state.dialogConfirm = false;
      // }
      clearData();
    };
    // 清空 数据
    const clearData = () => {
      state.secondParam = {};
      state.secondDetail = {};
      state.timeObj = {};
    };
    // 补0
    const addZore = (num) => {
      return `${num < 10 ? "0" + num : num}`;
    };
    // 获取当前时间的时分
    const initTimeP = () => {
      let myDate = Date.parse(new Date()) + 1000 * 60;
      const minDate = new Date(myDate);
      const maxDate = new Date(myDate + 3600 * 1000 * 2);
      state.timeObj.dateTime = `${minDate.getFullYear()}/${addZore(
        minDate.getMonth() + 1
      )}/${addZore(minDate.getDate())}`;
      state.timeObj.start = `${addZore(minDate.getHours())}:${addZore(
        minDate.getMinutes()
      )}`;
      if (minDate.getHours() > maxDate.getHours()) {
        state.timeObj.end = "23:59";
      } else {
        state.timeObj.end = `${addZore(maxDate.getHours())}:${addZore(
          maxDate.getMinutes()
        )}`;
      }
    };
    const toPath = (url) => {
      if (url === "/documentary") {
        $router.push(url + "?from=second");
      } else {
        $router.push(url);
      }
    };
    onMounted(() => {
      state.time = formatDate(Date.parse(new Date()));
      initTimeP();
      setTime();
      if ($store.state.user.token) {
        getTrading();
        getinfo();
      }
    });
    const getAll = () => {
      state.secondParam.deal_price = state.info?.balance;
    };
    return {
      state,
      closeSelect,
      setTime,
      getinfo,
      choiceTime,
      buy,
      placeOrder,
      countWinlose,
      cutinu,
      gettrading,
      getDetail,
      clearData,
      formatTimeZone,
      formatDate,
      getTimeZoneDate,
      initTimeP,
      addZore,
      refresh,
      transferNumberChange,
      getTrading,
      formatDecimal,
      getProfit,
      onConfirm,
      onCancel,
      isVerified,
      isFollow,
      revokeOrder,
      rideFix,
      toPath,
      // toPath,
      decimalDigitsInputFilter,
      floorDigitsInputFilter,
      exceptFix,
      isProfitShow,
      virtual_wallet,
      CountDealPrice,
      getAll,
      addFix,
      reduceFix,
      // disabledHours
    };
  },
};
</script>

<style scoped lang="less">
.activetab {
  padding: 8px;
  border-radius: 50px;
}
.mb-20 {
  margin-bottom: 20px;
}
.mb-32 {
  margin-bottom: 32px;
}
.mb-12 {
  margin-bottom: 12px;
}
.mb-2 {
  margin-bottom: 2px;
}
.mb-16 {
  margin-bottom: 16px;
}
.mr-4 {
  margin-inline-end: 4px;
}
.tabbox {
  width: 100%;
  border-bottom: 1px solid;
}
.tab {
  min-height: 21px;
  line-height: 21px;
  position: relative;
  text-align: start;
}
.title {
  border-bottom: 1px solid;
  padding-bottom: 12px;
}
.cus-select {
  width: 100%;
  height: 34px;
  border: 1px solid;
  padding: 0 8px;
}
.curent-time {
  width: 100%;
  background: rgba(46, 150, 246, 0.1);
  border-radius: 76px;
  padding: 6px;
}
.cus-select {
  width: 100%;
  height: 34px;
  border: 1px solid;
  padding: 0 8px;
  position: relative;
}
.select-num {
  width: 40px;
  height: 100%;
  line-height: 32px;
}
.num-box {
  position: absolute;
  top: 35px;
  right: -10px;
  padding: 10px;
  box-shadow: 0 8px 8px 0 rgba(0, 0, 0, 0.1);
  z-index: 1996;
  width: 100%;
}
.is-rtl {
  .num-box {
    right: auto;
    left: -18px;
  }
}
.num {
  min-height: 36px;
  line-height: 36px;
  width: 100%;
}
.num:hover {
  background: #f8f8f8;
}
.btn {
  // width: 84px;
  width: 100%;
  border-radius: 100px;
  height: 36px;
  line-height: 36px;
  margin: 12px 0;
}
.islogin {
  width: 100%;
  height: 36px;
  line-height: 36px;
  // display: block;
}
.block {
  display: block;
}
.lr-5 {
  margin: 0 5px;
}
.border {
  border: 1px solid @blue;
}
.confirm-box {
  padding: 0 20px;
}
.confirm-btn {
  width: 160px;
  height: 46px;
  line-height: 46px;
}
.top {
  min-width: 280px;
  height: 30px;
  border-radius: 76px;
  background: rgba(46, 150, 246, 0.1);
  margin: 0 auto 20px;
}
.continue {
  width: 100%;
  height: 46px;
  line-height: 46px;
}
.order-icon {
  width: 15px;
  height: 12px;
}
</style>
